<template>
  <UniDataCheckbox
    :value="modelValue"
    :localdata="itemList"
    :disabled="disabled"
    @change="handleChange"
  ></UniDataCheckbox>
</template>
<script setup lang="ts">
  import ActionSheet, { type ActionSheetItem } from '@/components/ActionSheet/index.vue';
  import { PromotionTypeEnum, ShowTypeEnum } from '@/enums/businessOpportunitiesEnum';
  import { propTypes } from '@/utils/propTypes';
  import { computed, ref, type PropType, watch } from 'vue';
  import UniDataCheckbox from '@/components/Form/uni_modules/uni-data-checkbox/uni-data-checkbox.vue';
  const props = defineProps({
    modelValue: {
      type: Number,
      default: undefined,
    },
    showType: Number as PropType<ShowTypeEnum>,
    joinFlag: propTypes.bool.def(false),
    disabled: propTypes.bool.def(false),
  });

  const emits = defineEmits(['update:modelValue']);

  const itemList = ref<ActionSheetItem[]>([
    {
      text: '申请跨会推广',
      des: '可推广到跨会供需库，与其他组织共享供需',
      value: PromotionTypeEnum.CrossConference,
      disabled: false,
    },
    {
      text: '仅会内流转',
      des: '仅在会内流转推广',
      value: PromotionTypeEnum.InternalOnly,
      disabled: false,
    },
  ]);

  watch(
    () => [props.showType, props.joinFlag],
    () => {
      itemList.value[0].disabled = !props.joinFlag || props.showType == ShowTypeEnum.PrivateShared;
      if (itemList.value[0].disabled) {
        emits('update:modelValue', itemList.value[1].value);
      }
    },
    { immediate: true },
  );

  const handleChange = (item: { detail: { value: number } }) => {
    emits('update:modelValue', item.detail.value);
  };
</script>
<style lang="scss" scoped></style>
